/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('dashscope', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CreateApiKeyRequest {
  expireHours?: long(name='ExpireHours', example='10'),
}

model CreateApiKeyResponseBody = {
  accessDeniedDetail?: string(name='AccessDeniedDetail', example='{"authAction":"dashscope:CreateApiKey","authPrincipalType":"SubUser","noPermissionType":"ExplicitDeny","EncodedDiagnosticMessage":"AQEAAAAAZCpw0zBEMjQwMjBELTQxMTktMUEyRC05MDdDLUFGMERFODM1RkE3Nw=="}'),
  data?: {
    apiKey?: string(name='ApiKey', example='xxx'),
    gmtCreate?: string(name='GmtCreate', example='2023-02-15 15:30:00'),
    gmtExpire?: string(name='GmtExpire', example='2023-02-15 15:30:00'),
    id?: long(name='Id', description='ApiKey ID', example='1'),
    latestActiveTime?: string(name='LatestActiveTime', example='2023-02-15 15:30:00'),
    userId?: string(name='UserId', example='1225979994735972'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='0D24020D-4119-1A2D-907C-AF0DE835FA77'),
  success?: boolean(name='Success', example='true'),
}

model CreateApiKeyResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateApiKeyResponseBody(name='body'),
}

async function createApiKeyWithOptions(request: CreateApiKeyRequest, runtime: Util.RuntimeOptions): CreateApiKeyResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.expireHours)) {
    body['ExpireHours'] = request.expireHours;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CreateApiKey',
    version = '2023-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createApiKey(request: CreateApiKeyRequest): CreateApiKeyResponse {
  var runtime = new Util.RuntimeOptions{};
  return createApiKeyWithOptions(request, runtime);
}

model DeleteApiKeyRequest {
  apiKeyId?: long(name='ApiKeyId', example='1'),
}

model DeleteApiKeyResponseBody = {
  accessDeniedDetail?: string(name='AccessDeniedDetail', example='{"authAction":"dashscope:CreateApiKey","authPrincipalType":"SubUser","noPermissionType":"ExplicitDeny","EncodedDiagnosticMessage":"AQEAAAAAZCpw0zBEMjQwMjBELTQxMTktMUEyRC05MDdDLUFGMERFODM1RkE3Nw=="}'),
  requestId?: string(name='RequestId', example='0D24020D-4119-1A2D-907C-AF0DE835FA77'),
  success?: boolean(name='Success', example='true'),
}

model DeleteApiKeyResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DeleteApiKeyResponseBody(name='body'),
}

async function deleteApiKeyWithOptions(request: DeleteApiKeyRequest, runtime: Util.RuntimeOptions): DeleteApiKeyResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.apiKeyId)) {
    body['ApiKeyId'] = request.apiKeyId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'DeleteApiKey',
    version = '2023-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function deleteApiKey(request: DeleteApiKeyRequest): DeleteApiKeyResponse {
  var runtime = new Util.RuntimeOptions{};
  return deleteApiKeyWithOptions(request, runtime);
}

model GetInvokeStatisticsRequest {
  apiKey?: string(name='ApiKey', description='ApiKey', example='51'),
  endTime?: long(name='EndTime', example='1679987099037'),
  modelName?: string(name='ModelName', example='moss_v1_dev'),
  region?: string(name='Region', example='cn-hangzhou'),
  startTime?: long(name='StartTime', example='1679987099037'),
  timeUnit?: string(name='TimeUnit', example='hour'),
}

model GetInvokeStatisticsResponseBody = {
  accessDeniedDetail?: string(name='AccessDeniedDetail', example='{"authAction":"dashscope:CreateApiKey","authPrincipalType":"SubUser","noPermissionType":"ExplicitDeny","EncodedDiagnosticMessage":"AQEAAAAAZCpw0zBEMjQwMjBELTQxMTktMUEyRC05MDdDLUFGMERFODM1RkE3Nw=="}'),
  data?: [ 
    {
      apiKey?: string(name='ApiKey', description='ApiKey', example='51'),
      metrics?: [ 
        {
          count?: long(name='Count', example='10000'),
          day?: string(name='Day', example='2023-03-17'),
          hour?: string(name='Hour', example='22'),
        }
      ](name='Metrics'),
      modelName?: string(name='ModelName', example='moss_v1_dev'),
      numUnit?: string(name='NumUnit'),
      region?: string(name='Region', example='cn-hangzhou'),
      statisticsUnit?: string(name='StatisticsUnit'),
      timeUnit?: string(name='TimeUnit', example='hour'),
    }
  ](name='Data'),
  requestId?: string(name='RequestId', example='A2A4C59F-E428-1774-B5F7-D491A4A61481'),
  success?: boolean(name='Success', example='true'),
}

model GetInvokeStatisticsResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetInvokeStatisticsResponseBody(name='body'),
}

async function getInvokeStatisticsWithOptions(request: GetInvokeStatisticsRequest, runtime: Util.RuntimeOptions): GetInvokeStatisticsResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.apiKey)) {
    query['ApiKey'] = request.apiKey;
  }
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.modelName)) {
    query['ModelName'] = request.modelName;
  }
  if (!Util.isUnset(request.region)) {
    query['Region'] = request.region;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  if (!Util.isUnset(request.timeUnit)) {
    query['TimeUnit'] = request.timeUnit;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetInvokeStatistics',
    version = '2023-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getInvokeStatistics(request: GetInvokeStatisticsRequest): GetInvokeStatisticsResponse {
  var runtime = new Util.RuntimeOptions{};
  return getInvokeStatisticsWithOptions(request, runtime);
}

model ListApiKeysRequest {
  pageNo?: long(name='PageNo', example='1'),
  pageSize?: long(name='PageSize', example='10'),
  validApiKey?: boolean(name='ValidApiKey', example='true'),
}

model ListApiKeysResponseBody = {
  accessDeniedDetail?: string(name='AccessDeniedDetail', example='{"authAction":"dashscope:CreateApiKey","authPrincipalType":"SubUser","noPermissionType":"ExplicitDeny","EncodedDiagnosticMessage":"AQEAAAAAZCpw0zBEMjQwMjBELTQxMTktMUEyRC05MDdDLUFGMERFODM1RkE3Nw=="}'),
  data?: {
    apiKeys?: [ 
      {
        apiKey?: string(name='ApiKey', description='Api Key', example='QqObiveQ79JtH9fHFtA4rKb490HqX12o370B1F97D1F211EDA6A6B606CFF6AAC0'),
        deleted?: boolean(name='Deleted', example='true'),
        gmtCreate?: string(name='GmtCreate', example='2023-04-03 15:36:15'),
        gmtExpire?: string(name='GmtExpire', example='2023-04-04 01:36:15'),
        id?: long(name='Id', description='Api Key Id', example='1'),
        latestActiveTime?: string(name='LatestActiveTime', example='2023-04-04 01:36:15'),
        userId?: string(name='UserId', example='1225979994735972'),
      }
    ](name='ApiKeys'),
    pageNo?: long(name='PageNo', example='1'),
    pageSize?: long(name='PageSize', example='10'),
    total?: long(name='Total', example='10'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='A2A4C59F-E428-1774-B5F7-D491A4A61481'),
}

model ListApiKeysResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ListApiKeysResponseBody(name='body'),
}

async function listApiKeysWithOptions(request: ListApiKeysRequest, runtime: Util.RuntimeOptions): ListApiKeysResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.pageNo)) {
    body['PageNo'] = request.pageNo;
  }
  if (!Util.isUnset(request.pageSize)) {
    body['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.validApiKey)) {
    body['ValidApiKey'] = request.validApiKey;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'ListApiKeys',
    version = '2023-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function listApiKeys(request: ListApiKeysRequest): ListApiKeysResponse {
  var runtime = new Util.RuntimeOptions{};
  return listApiKeysWithOptions(request, runtime);
}

model ListModelNamesResponseBody = {
  accessDeniedDetail?: string(name='AccessDeniedDetail', example='{"authAction":"dashscope:CreateApiKey","authPrincipalType":"SubUser","noPermissionType":"ExplicitDeny","EncodedDiagnosticMessage":"AQEAAAAAZCpw0zBEMjQwMjBELTQxMTktMUEyRC05MDdDLUFGMERFODM1RkE3Nw=="}'),
  data?: [ 
    {
      modelDesc?: string(name='ModelDesc', example='moss_v1_test'),
      modelName?: string(name='ModelName', example='moss_v1_test'),
      modelUnit?: string(name='ModelUnit'),
    }
  ](name='Data'),
  requestId?: string(name='RequestId', example='E1A07651-9600-1772-8C84-8DB33D9559A6'),
  success?: boolean(name='Success', example='true'),
}

model ListModelNamesResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: ListModelNamesResponseBody(name='body'),
}

async function listModelNamesWithOptions(runtime: Util.RuntimeOptions): ListModelNamesResponse {
  var req = new OpenApi.OpenApiRequest{};
  var params = new OpenApi.Params{
    action = 'ListModelNames',
    version = '2023-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function listModelNames(): ListModelNamesResponse {
  var runtime = new Util.RuntimeOptions{};
  return listModelNamesWithOptions(runtime);
}

model QueryOpenStatusRequest {
  region?: string(name='Region', example='cn-hangzhou'),
}

model QueryOpenStatusResponseBody = {
  accessDeniedDetail?: string(name='AccessDeniedDetail', example='{"authAction":"dashscope:CreateApiKey","authPrincipalType":"SubUser","noPermissionType":"ExplicitDeny","EncodedDiagnosticMessage":"AQEAAAAAZCpw0zBEMjQwMjBELTQxMTktMUEyRC05MDdDLUFGMERFODM1RkE3Nw=="}'),
  data?: {
    commoditiesOpenStatus?: [ 
      {
        cnName?: string(name='CnName'),
        commodity?: string(name='Commodity', example='dashscope_modelservice_public_cn'),
        describe?: string(name='Describe'),
        detailPage?: string(name='DetailPage', example='https://dashscope.aliyun.com/'),
        open?: boolean(name='Open', example='true'),
        openPage?: string(name='OpenPage', example='https://dashscope.aliyun.com/'),
        openTime?: string(name='OpenTime', example='1679987099037'),
        stop?: boolean(name='Stop', example='false'),
      }
    ](name='CommoditiesOpenStatus'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='93DDD399-8C57-11FF-8D0A-0382DA7D2F13'),
  success?: boolean(name='Success', example='true'),
}

model QueryOpenStatusResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: QueryOpenStatusResponseBody(name='body'),
}

async function queryOpenStatusWithOptions(request: QueryOpenStatusRequest, runtime: Util.RuntimeOptions): QueryOpenStatusResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.region)) {
    query['Region'] = request.region;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryOpenStatus',
    version = '2023-03-20',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function queryOpenStatus(request: QueryOpenStatusRequest): QueryOpenStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryOpenStatusWithOptions(request, runtime);
}

